package com.ljm.boot.rabbitmq.config;


import com.ljm.boot.rabbitmq.constant.*;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class DirectConfig {



    //--------direct路由模式---------
    @Bean
    public Queue queue_direct1() {
        return new Queue(RabbitMQConstant.DIRECT_QUEUE_1);
    }

    @Bean
    public Queue queue_direct2() {
        return new Queue(RabbitMQConstant.DIRECT_QUEUE_2);
    }

    @Bean
    public DirectExchange exchange_direct() {
        return new DirectExchange(RabbitMQConstant.DIRECT_EXCHANGE);
    }

    @Bean
    public Binding binding_direct1() {
        //将队列queue_direct1和交换机进行绑定，并给队列绑定路由
        return BindingBuilder.bind(new Queue(RabbitMQConstant.DIRECT_QUEUE_1)).to( new DirectExchange(RabbitMQConstant.DIRECT_EXCHANGE)).with(RabbitMQConstant.DIRECT_routingKey_1);
    }

    @Bean
    public Binding binding_direct2() {
        //将队列queue_direct2和交换机进行绑定，并给队列绑定路由
        return BindingBuilder.bind(new Queue(RabbitMQConstant.DIRECT_QUEUE_2)).to( new DirectExchange(RabbitMQConstant.DIRECT_EXCHANGE)).with(RabbitMQConstant.DIRECT_routingKey_2);
    }
}
